package com.qf.shop.order.config;

import com.qf.shop.order.interceptor.LoginInterceptor;
import com.qf.shop.order.interceptor.OrderDynamicDatasourceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private OrderDynamicDatasourceInterceptor orderDynamicDatasource;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns("/order/updateOrderStatus")
                .addPathPatterns("/**").
                order(1);
        registry.addInterceptor(orderDynamicDatasource)
                .excludePathPatterns("/order/updateOrderStatus")
                .addPathPatterns("/**").order(2);
    }
}
